package tasks;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.KeyEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;


public class TaskCfgDialog extends JDialog {

    private GridLayout gridLayout1 = new GridLayout(3,4, 10, 10);
    private JLabel mLabel = new JLabel("Manufacturer");
    private JRadioButton mButtonComp = new JRadioButton("Compaq");
    private JRadioButton mButtonHP = new JRadioButton("HP");
    private JRadioButton mButtonIntel = new JRadioButton("Intel");
    private JLabel qLabel = new JLabel("Quality");
    private JRadioButton qAverage = new JRadioButton("Average");
    private JRadioButton qGood = new JRadioButton("Good");
    private JRadioButton qBest = new JRadioButton("Best");
    private JLabel priceLabel = new JLabel("Price");
    private JTextField priceTextField = new JTextField("100");
    private JButton okButton = new JButton("OK");
    private JButton cButton = new JButton("Cancel");

    private ButtonGroup mGroup = new ButtonGroup();
    private ButtonGroup qGroup = new ButtonGroup();
    
    private static final String OK_COMMAND = "OK";
    private static final String CANCEL_COMMAND = "CANCEL";
    
    public TaskCfgDialog() {
        this(null, "", false);
    }

    public TaskCfgDialog(Frame parent, String title, boolean modal) {
        super(parent, title, modal);
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        //set properties
        this.setSize(new Dimension(321, 110));
        mButtonComp.setSelected(true);
        qAverage.setSelected(true);
        okButton.setMnemonic(KeyEvent.VK_K);
        okButton.setActionCommand(OK_COMMAND);
        cButton.setMnemonic(KeyEvent.VK_A);
        cButton.setActionCommand(CANCEL_COMMAND);
        //group buttons
        mGroup.add(mButtonComp);
        mGroup.add(mButtonHP);
        mGroup.add(mButtonIntel);
        qGroup.add(qAverage);
        qGroup.add(qGood);
        qGroup.add(qBest);
        //add components to panel
        this.getContentPane().setLayout(gridLayout1);
        this.getContentPane().add(mLabel, null);
        this.getContentPane().add(mButtonComp, null);
        this.getContentPane().add(mButtonHP, null);
        this.getContentPane().add(mButtonIntel, null);
        this.getContentPane().add(qLabel, null);
        this.getContentPane().add(qAverage, null);
        this.getContentPane().add(qGood, null);
        this.getContentPane().add(qBest, null);
        this.getContentPane().add(priceLabel, null);
        this.getContentPane().add(priceTextField, null);
        this.getContentPane().add(okButton, null);
        this.getContentPane().add(cButton, null);
    }
    
    public void actionPerformed(ActionEvent e) {
        String comm = e.getActionCommand();
        if(comm.equals(OK_COMMAND)) {
          
        } else if(comm.equals(CANCEL_COMMAND)) {
            
        }
    }
}
